package com.zky.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.zky.service.StudentService;
import com.zky.domain.dto.PageDto;
import com.zky.domain.po.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import com.zky.domain.po.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zky.domain.po.PageResult;

@RestController
@RequestMapping("/student")
@Api(tags = "Student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping
    @ApiOperation("add Student")
    public Result add(@RequestBody Student entity) {

        return Result.ok(studentService.save(entity));

    }

    @DeleteMapping("/{id}")
    @ApiOperation("delete Student")
    public Result delete(@PathVariable Integer id) {

        return Result.ok(studentService.removeById(id));

    }

    @DeleteMapping()
    @ApiOperation("delete Student by ids")
    public Result deleteByIds(@RequestBody List<Integer> ids) {

        return Result.ok(studentService.removeByIds(ids));

    }


    @PutMapping
    @ApiOperation("update Student")
    public Result update(@RequestBody Student entity) {

        return Result.ok(studentService.updateById(entity));

    }

    @GetMapping("/{id}")
    @ApiOperation("get Student by id")
    public Result get(@PathVariable Integer id) {

        return Result.ok(studentService.getById(id));

    }

    @GetMapping
    @ApiOperation("get Student by pageDto")
    public Result list(PageDto pageDto) {
        Page<Student>page = new Page<>(pageDto.getPageNo(),pageDto.getPageSize());
        Page<Student>page1 = studentService.page(page);
        return PageResult.of(page1.getRecords(),page1.getTotal());
    }

    @GetMapping("list")
    @ApiOperation("get All")
    public Result findAll() {
        List<Student> list = studentService.list();
        return Result.ok(list);

    }


}
